package com.qkbb.admin.kuibu.qkbb.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.qkbb.admin.kuibu.R;
import com.qkbb.admin.kuibu.qkbb.funcation.HttpPut;
import com.qkbb.admin.kuibu.qkbb.funcation.ImageDownloadSDCardCacheHelper;
import com.qkbb.admin.kuibu.qkbb.funcation.OSShelp;
import com.qkbb.admin.kuibu.qkbb.url.Url;
import com.qkbb.admin.kuibu.qkbb.view.TitleBarView;

import java.net.URL;

import static com.qkbb.admin.kuibu.R.id.find_friend_edittext;
import static com.qkbb.admin.kuibu.R.id.friend_information_id;
import static com.qkbb.admin.kuibu.R.id.name;

public class FriendIformation extends Activity {
    String nickname;
    String userid;
    String photo;
    private TitleBarView titleBarView;
    ImageView imageView;
    TextView regiontext;
    TextView nametext;
    TextView Idtext;
    Button button;
    EditText editText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_friend_iformation);
        Init();
        SetData();
        SetOnClick();

    }

    private void Init() {
        Intent intent=getIntent();
        nickname=intent.getStringExtra("nickname");
        userid=intent.getStringExtra("userid");
        photo=intent.getStringExtra("photo");
        titleBarView= (TitleBarView) findViewById(R.id.friend_information_titlebar);
        nametext= (TextView) findViewById(R.id.friend_information_name);
        Idtext= (TextView) findViewById(friend_information_id);
        imageView= (ImageView) findViewById(R.id.friend_information_image);
        editText= (EditText) findViewById(R.id.friend_information_edittext);
        button= (Button) findViewById(R.id.friend_information_addfriend);
        titleBarView.setCenterTexiView("添加好友");
        titleBarView.settextColor(Color.WHITE);

    }
    private void SetData(){
        Idtext.setText(userid);
        nametext.setText(nickname);
        OSShelp osShelp=new OSShelp(getApplication());
        String url=osShelp.getBitmap(nickname);
        new ImageDownloadSDCardCacheHelper().myDownloadImageSDCardCache(getApplication(), url, imageView, photo, 1);
    }
    private void SetOnClick(){
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String reason=editText.getText().toString();
                String type[]={"friendid","reason"};
                String data[]={userid,reason};
                new HttpPut(getApplication()).PostData(type,data,Url.POSTADDFRIEND);
            }
        });
    }
}
